package top.continew.admin.webapi.sport;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import top.continew.starter.extension.crud.enums.Api;

import io.swagger.v3.oas.annotations.tags.Tag;

import org.springframework.web.bind.annotation.*;

import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.continew.starter.extension.crud.controller.BaseController;
import top.continew.admin.sport.model.query.ProjectRefereeQuery;
import top.continew.admin.sport.model.req.ProjectRefereeReq;
import top.continew.admin.sport.model.resp.ProjectRefereeDetailResp;
import top.continew.admin.sport.model.resp.ProjectRefereeResp;
import top.continew.admin.sport.service.ProjectRefereeService;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.web.model.R;

import java.util.List;

/**
 * 项目裁判管理 API
 *
 * @author xiahaike
 * @since 2024/09/15 09:22
 */
@Tag(name = "项目裁判管理 API")
@RestController
@CrudRequestMapping(value = "/sport/projectReferee", api = {Api.PAGE, Api.GET, Api.ADD, Api.UPDATE, Api.DELETE, Api.EXPORT})
public class ProjectRefereeController extends BaseController<ProjectRefereeService, ProjectRefereeResp, ProjectRefereeDetailResp, ProjectRefereeQuery, ProjectRefereeReq> {

        @Resource
        private ProjectRefereeService projectRefereeService;

        @Operation(summary = "分页查询列表", description = "分页查询列表")
        @ResponseBody
        @GetMapping
        @Override
        public R<PageResp<ProjectRefereeResp>> page(ProjectRefereeQuery projectRefereeQuery, @Validated PageQuery pageQuery) {
            this.checkPermission(Api.LIST);
            PageResp<ProjectRefereeResp> projectRefereeRespPageResp = projectRefereeService.myPage(projectRefereeQuery, pageQuery);
            return R.ok(projectRefereeRespPageResp);
        }

        @Operation(summary = "批量添加裁判", description = "批量添加裁判")
        @PostMapping("/batchAdd")
        public R<Void> batchAdd(@RequestBody ProjectRefereeReq projectRefereeReq) {
            this.checkPermission(Api.ADD);
            List<Long> refereeIds = projectRefereeReq.getRefereeIds();
            Long projectId = projectRefereeReq.getProjectId();
            projectRefereeService.batchAdd(projectId, refereeIds);
            return R.ok("添加裁判成功");
        }
}